package com.google.gwt.gfx.client.graphics.vml;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.gfx.client.graphics.Ellipse;
import com.google.gwt.gfx.client.style.AnchorStyle;
import com.google.gwt.user.client.DOM;

public class VMLEllipse extends Ellipse {

	private AnchorStyle anchorRef;

	public VMLEllipse() {
		super(DOM.createElement("v:oval"));

		anchorRef = new AnchorStyle(this) {

			@Override
			public int getLeft() {
				return getElement().getOffsetLeft() + getRadiusWidth();
			}

			@Override
			public int getTop() {
				return getElement().getOffsetTop() + getRadiusHeight();
			}

			@Override
			public void setLeft(int left) {
				getElement().getStyle().setLeft(left - getRadiusWidth(),
						Unit.PX);
			}

			@Override
			public void setTop(int top) {
				getElement().getStyle()
						.setTop(top - getRadiusHeight(), Unit.PX);
			}

		};
	}

	@Override
	public int getRadiusHeight() {
		return getElement().getOffsetHeight() / 2;
	}

	@Override
	public int getRadiusWidth() {
		return getElement().getOffsetWidth() / 2;
	}

	@Override
	public AnchorStyle anchor() {
		return anchorRef;
	}

	@Override
	public void setRadiusHeight(int radiusY) {
		getElement().getStyle().setHeight(2 * radiusY, Unit.PX);
	}

	@Override
	public void setRadiusWidth(int radiusX) {
		getElement().getStyle().setWidth(2 * radiusX, Unit.PX);
	}

}
